/* Note: the data used in this analysis was collected as part of the China Policy Barometer survey wave in 2019. For questions 
or additional variables, consult Dimitar D. Gueorguiev, Syracuse University */ 

use "/Users/ddgueorg/Dropbox/China Policy Barometer/2019/data/cpb_survey_2019_unweighted_hk_protest.dta", clear 

/************************/
/* Setting up the HK Experiment variables */
/************************/
egen hk_support=rowtotal(hk_rights_peaceful hk_rights_violent hk_autonomy_peaceful hk_autonomy_violent)
replace hk_support=. if hk_rights_peaceful==. & hk_rights_violent==. & hk_autonomy_peaceful==. & hk_autonomy_violent==. 
g hk_treat=1 if hk_rights_peaceful!=. 
replace hk_treat=2 if hk_rights_violent!=. 
replace hk_treat=3 if hk_autonomy_peaceful!=. 
replace hk_treat=4 if hk_autonomy_violent!=. 
g hk_treat2= hk_rights_violent!=. | hk_autonomy_violent!=. 
g democracy=  hk_rights_peaceful!=. |  hk_rights_violent!=.
replace democracy=. if hk_rights_peaceful==. & hk_rights_violent==. & hk_autonomy_peaceful==. & hk_autonomy_violent==. 
g violent=  hk_autonomy_violent!=. |  hk_rights_violent!=.
replace violent=. if hk_rights_peaceful==. & hk_rights_violent==. & hk_autonomy_peaceful==. & hk_autonomy_violent==. 
g hk_support2= hk_support==2
replace hk_support2=. if hk_support==1 | hk_support==.

/************************/
/* Setting up time variables */
/************************/
split startdate, p(" ", "/")
destring startdate1 startdate2 startdate3, replace
replace startdate3= startdate3+2000
gen date = mdy(startdate1, startdate2, startdate3)
gen after = date> 21751 /* This dummy designates responses collected after the liaison incident */ 

/************************/
/* Labeling */
/************************/
label define HK_Treat 1 "Democracy Peaceful" 2 "Democracy Violent" 3 "Seperatist Peaceful" 4 "Seperatist Violent"
label define HK_Treat_2 0 "Peaceful" 1 "Violent" 
label define HK_Treat_3 0 "Democracy" 1 "Violent" 
label values hk_treat HK_Treat
label values hk_treat2 HK_Treat_2
label define hk_support 1 "No opinion" 2 "Sympathy" 3 "Condemn"
label values hk_support hk_support
label variable income "Income (1-5, positive)"
label variable male "Male"
label variable ccp_member "CCP Member"
label variable violent "Violence"
label variable democracy "Democracy"

/************************/
/* Table 2 Sample Demographics */
/************************/
tabulate age hk_treat, chi2
tabulate edu hk_treat, chi2
tabulate male hk_treat, chi2
tabulate income hk_treat, chi2

/************************/
/* Figure 2 Suport for Protests */
/************************/
graph hbar (percent), over(hk_support, label(nolabel)) over(hk_treat, label(angle(forty_five))) ///
bar(1, fcolor(none) lcolor(black) lwidth(medium) ///
lpattern(solid)) bargap(.01) outergap(.05) blabel(group) ytitle(Sample Proportion) ylabel(, nogrid)


/************************/
/* Table 3 Experimetal Results */
/************************/
eststo: logit hk_support2 i.violent, robust
eststo: logit hk_support2 i.democracy##i.violent, robust
eststo: logit hk_support2 i.democracy##i.violent male edu income age after ccp_member, robust
eststo: logit hk_support2 i.democracy##violent##ccp_member after male edu income age , robust
eststo: logit hk_support2 i.democracy##violent##after ccp_member male edu income age, robust
esttab, b(%9.3fc) replace ///
se r2 nobaselevels star(* 0.10 ** 0.05 *** 0.001) eqlabels("") title(Experimental Results\label{tab:hk.logit}) ///
compress mgroups("Average Treatment" "Conditional", pattern(1 0 0 1 0)  ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
mtitles("Tactics" "Objectives" "Controls" "CCP Member" "Post-Liason" ) ///
drop () order ()
eststo clear 

/************************/
/* Table A1 Experimetal Results using Multinomial Logit */
/************************/
eststo clear  
eststo: mlogit hk_support i.violent, robust base(1)
eststo: mlogit hk_support i.violent##i.democracy, robust base(1)
eststo: mlogit hk_support2 i.democracy##i.violent male edu income age after ccp_member, robust base(1)
eststo: mlogit hk_support2 i.democracy##violent##ccp_member after male edu income age, robust base(1)
eststo: mlogit hk_support2 i.democracy##violent##after ccp_member male edu income age, robust base(1)
esttab, b(%9.3fc) replace ///
se r2 nobaselevels star(* 0.10 ** 0.05 *** 0.001) eqlabels("") title(Experimental Results (Multinomial Logit)\label{tab:hk.mlogit}) ///
compress mgroups("Average Treatment" "Conditional", pattern(1 0 0 1 0)  ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
mtitles("Tactics" "Objectives" "Controls" "CCP Members" "post-Liaison") ///
drop () order ()

/************************/
/* Figure 4: Priming Propaganda Results */
/************************/
preserve
collapse hk_support2, by(edate hk_treat)
drop if hk_treat==.
reshape wide hk_support, i(edate) j(hk_treat)
g dem_diff=hk_support22-hk_support21
g sep_diff=hk_support24-hk_support23
g violence_diff=(hk_support21+hk_support23) - (hk_support22+hk_support24)
egen mean_support= rowmean(hk_support21 hk_support22 hk_support23 hk_support24)
twoway (lowess dem_diff edate, lpattern(shortdash)) (lowess sep_diff edate, lpattern(longdash))  (lowess mean_support edate, lwidth(thick) yaxis(2)), ///
ytitle(Violence Difference) legend(rows(3) order(1 "Democracy Difference" 2 "Seperatist Difference" 3 "Protest Sympathy")  position(1) ring(0)) ///
xtitle(, size(zero)) ytitle(Protest Sympathy, axis(2))
